package com.zrf.springCloudTest.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 消费者
 * @author zrf
 *         Created by zrf on 2016/8/27.
 */
@RestController
public class ComputeController {
    /**
     * 日志
     */
    private Logger logger = LoggerFactory.getLogger(getClass());
    /**
     * springCloud 服务发现的客户端
     */
    @Autowired
    private DiscoveryClient discoveryClient;

    /**
     * 添加操作 a+b
     * @param a 参数a
     * @param b 参数b
     * @return a+b的返回值
     */
    @RequestMapping("add")
    public Integer add(Integer a, Integer b){
        ServiceInstance localServiceInstance = discoveryClient.getLocalServiceInstance();
        Integer result = a + b;
        logger.info("/add,host:" + localServiceInstance.getHost() + ",server_id:" + localServiceInstance.getServiceId()
                + ",result:" + result);

        return result;
    }
}
